package cn.yiueil.processor;

import cn.yiueil.entity.Pokemon;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class PokemonBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization ----");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization ---");
        if (bean instanceof Pokemon) {
            ((Pokemon) bean).setName("蒜头王八");
        }
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
